package com.eyaomall.wxmanage.service;

import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import com.lycheeframework.core.cmp.api.annotation.ApiReview;
import com.lycheeframework.core.common.util.StringUtil;

public class ScanApiReview {
	
	@SuppressWarnings("rawtypes")
	public static void main(String[] args) throws ClassNotFoundException {
		File file = new File("/Users/FlounyCaesar/项目/beyond_house/phoenix/phoenix_API/target/classes/com/fsfo2o/phoenix/api/controller");
		File[] files = file.listFiles();
		if (files == null || files.length <=0) return;
		
		List<Class> clazzs = new ArrayList<Class>();
		for (File f: files) {
			String filename = f.getName();
			int dot = filename.lastIndexOf('.');   
            if ((dot >-1) && (dot < (filename.length()))) {
            	filename = filename.substring(0, dot);
            }
            
            if (StringUtil.isEmpty(filename)) continue;
            
            clazzs.add(Class.forName("com.fsfo2o.phoenix.api.controller." + filename));
		}
		
		List<String> newList = new ArrayList<String>();
		for (int i = 0; i < clazzs.size(); i++) {
			Class clzz = clazzs.get(i);
			if (!hasApiReview(clzz)){
				newList.add(clzz.getName());
			}
		}
		for (String name: newList) {
			System.out.println(name);
		}
	}
	
	private static boolean hasApiReview(Class<?> clazz) {
		Annotation[] annotations = clazz.getAnnotations();
		boolean flag = false;
		for (int i = 0; i < annotations.length; i++) {
			if (annotations[i] instanceof ApiReview) return true;
		}
		
		if (!flag) {
			Method[] methods = clazz.getMethods();
			for (Method method: methods) {
				if (method.getAnnotation(ApiReview.class) != null) return true;
			}
		}
		
		return flag;
	}
}